//
//  BaseTableViewController.swift
//  XDweibo
//
//  Created by HanXingda on 15/6/24.
//  Copyright © 2015年 韩兴达. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,LoginVistorViewDelegate {

    var login = sharedUserAccount != nil
    var vistorView : LoginVistorView?
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    
    override func loadView() {
//         login = false
        print("用户登录\(login)")
        login ? super.loadView() : setVistorLoginView()
        vistorView?.loginButton.addTarget(self, action: "loginButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
        vistorView?.registerButton.addTarget(self, action: "registerButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
        
    }

    func setVistorLoginView () {
        vistorView = LoginVistorView()
        vistorView?.delegate = self
        view = vistorView!
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonClicked")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerButtonClicked")
        
    }
    
    func loginButtonClicked() {
        print("登录")
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
        
    }
    func registerButtonClicked() {
        print("注册")
    }
    

}
